// =========== calculate difference =========== //
class cdiff {
  // === calculate diff by 'abs' or 'square' === //
  int calculate(int buf1[], int buf2[], String mode) {
    int value = 0;

    if (mode == "square") {
      // bascially use 'abs' mode is ok.
      for (int i = 0; i < LEN; i++) {
        int b1 = buf1[i];
        int b2 = buf2[i];
        value += pow(b1 - b2, 2);
      }
    } else if (mode == "abs") {
      for (int i = 0; i < LEN; i++) {
        int b1 = buf1[i];
        int b2 = buf2[i];
        value += abs(b1 - b2);
      }
    } else {
      println("\n\n!!! WRONG MODE !!!");
      exit();
    }
    return value;
  }

  // === member var === //
  private final int LEN = 100; // raw data / pattern same len fixed to 100
};
